/**
 * @author SilverBiology, LLC
 * @website http://code.google.com/p/gbif-spreadsheet-processor/
*/
Ext.namespace('GBIF');
Ext.namespace('GBIF.GeoSpatial')

GBIF.GeoSpatial.WFSCapabilitiesGrid = function(config){	

	var sm = new Ext.grid.CheckboxSelectionModel({
		checkOnly: true
	}); 
    
	var store = new GeoExt.data.WFSCapabilitiesStore({
		url: '../resources/api/getcapabilities-proxy.php'
	});
    
	Ext.apply(this,config,{
			store: store
		,	loadMask:true
		,	sm: sm
		,	columns: [
					sm
				,	{header: "Title", dataIndex: "title", sortable: true}
				,	{header: "Name", dataIndex: "name", sortable: true, hidden:true}
				,	{header: "Value", dataIndex: "srs", sortable: true}
				,	{header: "Format", dataIndex: "format", sortable: true}
			]
		, listeners: {
				rowcontextmenu: this.previewmenu 
			}		
	});

	GBIF.GeoSpatial.WFSCapabilitiesGrid.superclass.constructor.call(this, config);
};

Ext.extend(GBIF.GeoSpatial.WFSCapabilitiesGrid,Ext.grid.GridPanel, {
	
		layerData: function(){
			if (this.getSelectionModel().getSelected()) {
				var rowdata = this.getSelectionModel().getSelections();
				this.fireEvent('addLayer', rowdata,this);
			} else {
				GBIF.GeoSpatial.Notice.msg(this.txtError,this.txtLayerTypeError);
			}
		}
	
	,	previewmenu:function(grid, index, e){
			var indexI = index;
			var menu = new Ext.menu.Menu({
				items: [{
						text: 'Preview'
					, scope: this
					,	handler: function(){
							this.getSelectionModel().selectRow(indexI,true);
							var rowdata = this.getSelectionModel().getSelections();
							this.fireEvent('previewLayers', rowdata, this);
						}
				}]
			});
			e.stopEvent();
			menu.showAt(e.getXY());
		}	
});